icon theme: Add a texture cache
authorMatthias Clasen <mclasen@redhat.com>
Mon, 23 Oct 2017 05:51:45 +0000 (07:51 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 23 Oct 2017 06:07:35 +0000 (08:07 +0200)
Return cached textures for icons. This lets us avoid duplicate
texture uploads for icons whose surfaces we already cache.

docs/reference/gtk/gtk4-sections.txt
gtk/gtkicontheme.c
gtk/gtkicontheme.h

index 57cb5e9ca115cf1dce12a3839927f0a3c1545908..3cc532780e5063c8167d259178d905d214027fea 100644 (file)
@@ -5446,6 +5446,7 @@ gtk_icon_theme_lookup_by_gicon_for_scale
 gtk_icon_theme_load_icon
 gtk_icon_theme_load_icon_for_scale
 gtk_icon_theme_load_surface
+gtk_icon_theme_load_texture
 gtk_icon_theme_list_contexts
 gtk_icon_theme_list_icons
 gtk_icon_theme_get_icon_sizes
index 2a663c55e85fa594cb30c47cc1a0241cda5100e8..64842b4ccd75fcd2ad7c5c1d5821b7627b62e98a 100644 (file)
@@ -225,6 +225,7 @@ struct _GtkIconInfo
    */
   GdkPixbuf *pixbuf;
   GdkPixbuf *proxy_pixbuf;
+  GskTexture *texture;
   GError *load_error;
   gdouble unscaled_scale;
   gdouble scale;
@@ -4004,6 +4005,40 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info,
   return icon_info->proxy_pixbuf;
 }
 
+/**
+ * gtk_icon_info_load_texture:
+ * @icon_info: a #GtkIconInfo
+ *
+ * Returns a texture object that can be used to render the icon
+ * with GSK.
+ *
+ * Returns: (transfer full): the icon texture; this may be a newly
+ *     created texture or a new reference to an exiting texture, so you must
+ *     not modify the icon. Use g_object_unref() to release your
+ *     reference.
+ *
+ * Since: 3.94
+ */
+GskTexture *
+gtk_icon_info_load_texture (GtkIconInfo *icon_info)
+{
+  if (!icon_info->texture)
+    {
+      GdkPixbuf *pixbuf;
+
+      pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
+      icon_info->texture = gsk_texture_new_for_pixbuf (pixbuf);
+      g_object_unref (pixbuf);
+
+      g_object_add_weak_pointer (icon_info->texture, &icon_info->texture);
+    }
+
+  if (icon_info->in_cache != NULL)
+    ensure_in_lru_cache (icon_info->in_cache, icon_info);
+
+  return g_object_ref (icon_info->texture);
+}
+
 /**
  * gtk_icon_info_load_surface:
  * @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
index a76a97890e100b73d948f97346397eea390af2d5..4f697179519d0673acb53a70d68baf1982e6c5b6 100644 (file)
@@ -25,6 +25,7 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gdk/gdk.h>
 #include <gtk/gtkstylecontext.h>
+#include <gsk/gsk.h>
 
 G_BEGIN_DECLS
 
@@ -293,6 +294,9 @@ GDK_AVAILABLE_IN_3_10
 cairo_surface_t *     gtk_icon_info_load_surface       (GtkIconInfo   *icon_info,
                                                        GdkWindow     *for_window,
                                                        GError       **error);
+GDK_AVAILABLE_IN_3_94
+GskTexture *          gtk_icon_info_load_texture       (GtkIconInfo   *icon_info);
+
 GDK_AVAILABLE_IN_3_8
 void                  gtk_icon_info_load_icon_async   (GtkIconInfo          *icon_info,
                                                       GCancellable         *cancellable,